<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="author" content="oto">
<title><{:C('SYSTEM_NAME')}></title>
	<!--<script src="https://webapi.amap.com/maps?v=1.4.10&key=7b5b68d8eedd376a331579722714be19&callback=init"></script>-->
	<!-- <script src="//a.amap.com/jsapi_demos/static/china.js"></script> -->
	<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.10&key=7b5b68d8eedd376a331579722714be19&plugin=AMap.MarkerClusterer"></script>
<include file="Common:head" />
</head>
<body id="layout-body" class="easyui-layout">
<!-- 头部 -->
<div id="toparea" data-options="region:'north',border:false,height:70">
	<input type="hidden" id="aaaa" value="<{$position}>">
	<!--<div><{$position}></div>-->
	<div id="topmenu" class="easyui-panel" data-options="fit:true,border:false">
		<ul class="nav" style="margin: 0px;line-height: 43px;">
			<foreach name="menuList" item="menu">
				<li><a href="javascript:void(0);"  onclick="baseModule.getLeft(<{$menu.id}>,'<{$menu.name}>', this)"><{$menu.name}></a></li>
			</foreach>
				<li>
					<div class="logo-img"><img src="__STATIC__/img/nav_logo_small.png"></div>
				</li>
				<li>
					<div class="logo-text">
							TOMOBO智慧消防系统
						</div>
				</li>
			</ul>
		<ul class="nav-right">
			<li style="padding: 14px">
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true" onclick="window.open('http://fire.tomobo.com/big/index.html')">大屏数据</a>
				<a href="javascript:void(0);" class="easyui-splitbutton" data-options="menu:'#toparea-user-info-box',iconCls:'iconfont icon-user'"><{$userInfo.rolename}></a>
				<a href="javascript:void(0);" class="easyui-splitbutton" data-options="menu:'#toparea-help-box',iconCls:'iconfont icon-help'">帮助</a>
				<div id="toparea-user-info-box">
					<div><{$userInfo.username}></div>
					<div class="menu-sep"></div>
					<div onclick="baseModule.userinfo()">个人信息</div>
					<div onclick="baseModule.password()">修改密码</div>
					<div class="menu-sep"></div>
					<div onclick="baseModule.logout()">退出登录</div>
				</div>
				<div id="toparea-help-box">
					<!-- <div onclick="$.messager.alert('问题反馈', '请发邮件到674086532@qq.com提交反馈，谢谢！', 'info');">问题反馈</div>
					<div class="menu-sep"></div>
					<div onclick="baseModule.clearCache()">更新缓存</div>
					<div>
						<span>切换主题</span>
						<div id="toparea-help-theme-box">
							<div onclick="baseModule.theme(this)" theme="default">系统默认</div>
							<div onclick="baseModule.theme(this)" theme="gray">Gray</div>
							<div onclick="baseModule.theme(this)" theme="bootstrap">Bootstrap</div>
							<div onclick="baseModule.theme(this)" theme="metro">Metro</div>
						</div>
					</div>
					<div class="menu-sep"></div>
					<div onclick="baseModule.systemInfo()">服务器信息</div> -->
					<!-- <div onclick="$.messager.alert('关于', '版本号：<{:C('SYSTEM_VERSION')}><br /><br />联系QQ：674086532', 'info');">关于</div> -->
					<div onclick="$.messager.alert('关于', '版本号：<{:C('SYSTEM_VERSION')}>', 'info');">关于</div>
				</div>
			</li>
		</ul>
		<div style="clear:both;border-bottom:none;border-left:none;border-right:none"></div>
	</div>
</div>
<style>

	.datagrid-row {
		height: 32px;
	}
	.accordion .accordion-header {
		background: #E0ECFF;
		/*margin-top: 0px;*/
	}
	.tree-node{
		height:18px;
		padding: 10px 0;
	}
	.tree-title{
		font-size: 14px;
	}
	.panel-title{
		font-size: 14px;
	}
</style>
<!-- 左侧菜单 -->
<div id="leftarea" data-options="iconCls:'icons-application-application_side_boxes',region:'west',title:'加载中...',split:true,width:270">
	<div id="leftmenu" class="easyui-accordion" data-options="fit:false,border:false,multiple:false,selected:1"></div>
</div>

<!-- 内容 -->
<div id="mainarea" data-options="region:'center'">
	<div id="pagetabs" class="easyui-tabs" data-options="tabPosition:'top',fit:true,border:false,plain:false">
		<div title="电子地图" href="<{:U('admin/Index/public_main')}>" data-options="cache:false"></div>
	</div>
</div>

<!-- 公共部分 -->
<div id="globel-dialog-div" class="word-wrap" style="line-height:1.5"></div>
<div id="globel-dialog2-div" class="word-wrap" style="line-height:1.5"></div> <!-- 特殊情况可能需要弹出第2个弹出层 -->

<script type="text/javascript">
  window.baseModule = {
	dialog:   '#globel-dialog-div',

	//初始化
	init: function(){
        //站长初次登录需要修改密码
        var is_modified = <{$userInfo.is_modified}>;

		$('#topmenu > ul.nav > li:first > a:first').click(); //默认选中第一个菜单
		this.tip();
        //给展开折叠按钮，赋值
		this.setToggleBtn();
	},
	setToggleBtn:function(){
		var body = $('#layout-body');
		//body.hasClass('body_layout_west_collapse') && body.removeClass('body_layout_west_collapse');

		var layout_button = $('#layout-body > .layout-split-west > .panel-header:first-child > .panel-tool');
        var html = '<a href="javascript:void(0)" class="layout-button-enpand-label"></a>';
		var left = $('.layout-button-left');
        var right_label;
		var right =  $('.layout-button-right');
		
		var delay = 800;//ms
		var disabledClass = 'no-click';
        left.click(function () {
			$that = $(this);
			$that.parent().addClass(disabledClass);
            if(theme != 'material'){
                return;
            }
            right_label = $('.layout-button-enpand-label');
            if (right_label.length <=0){
                layout_button.append(html);
                $('.layout-button-enpand-label').click(function () {
					$that = $(this);
					$that.parent().addClass(disabledClass);
                    if(theme != 'material'){
                        return;
                    }
                    body.layout('expand', 'west');
                    body.hasClass('body_layout_west_expand') || body.addClass('body_layout_west_expand');
                    body.hasClass('body_layout_west_collapse') && body.removeClass('body_layout_west_collapse');
					setTimeout(function(){
						$that.parent().removeClass('no-click');
					}, delay);
                })
            }
            body.hasClass('body_layout_west_collapse') || body.addClass('body_layout_west_collapse');
            body.hasClass('body_layout_west_expand') && body.removeClass('body_layout_west_expand');
			setTimeout(function(){
				$that.parent().removeClass('no-click');
			}, delay);
        });
	},
	//登录默认提示
	tip: function(){
		$.messager.show({
			title:'登录提示',
			width:'300',
			heght:'200',
			msg:'您好！<{$userInfo.username}> 欢迎回来！<br/>最后登录时间：<if condition="$userInfo['lastlogintime']"><{$userInfo.lastlogintime|date='Y-m-d H:i:s',###}><else/>-</if><br/>最后登录IP：<{$userInfo.lastloginip}>',
			timeout:5000,
			showType:'slide'
		});
	},

	//切换主题
	theme: function(that){
		var theme = that.getAttribute('theme');
		$('link[rel*=style][title]').each(function(i){
			this.disabled = true;
			if (this.getAttribute('title') == theme) this.disabled = false;
		});
		$('iframe').contents().find('link[rel*=style][title]').each(function(i){
			this.disabled = true;
			if (this.getAttribute('title') == theme) this.disabled = false;
		});
		$.cookie('theme', theme, {path:'/', expires:3650});
	},

	//移除左侧栏目  TODO 发现需要执行两次才能彻底清除
	removeLeft: function(stop, titles){
		var pp = $("#leftmenu").accordion("panels");
		$.each(pp, function(i, n) {
			if(n){
				var t = n.panel("options").title;
				if(titles && titles.length){
					for(var k = 0; k < titles.length; k++){
						if(titles[k] == t) $("#leftmenu").accordion("remove", t);
					}
				}else{
					$("#leftmenu").accordion("remove", t);
				}
			}
		});
		var pp = $('#leftmenu').accordion('getSelected');
		if(pp) {
			var t = pp.panel('options').title;
			if(titles && titles.length){
				for(var k = 0; k < titles.length; k++){
					if(titles[k] == t) $("#leftmenu").accordion("remove", t);
				}
			}else{
				$("#leftmenu").accordion("remove", t);
			}
		}
		if(!stop) this.removeLeft(true, titles);
	},
	leftMenuIcon:{
		'系统首页':'icon-home',
		'报警中心':'icon-alarm',
		'运维管理':'icon-icon-',
		'设备管理':'icon-shebeiguanli',
		'用户设置':'icon-setting-user',
		'系统设置':'icon-xitongshezhi',
		'默认图标':'icon-g_default_on'
	},
	//获取左侧栏目
	getLeft: function(menuid, title, object){
		var that = this;

		//加个判断，防止多次点击重复加载
		var options = $('body').layout('panel', 'west').panel('options');
		if(title == options.title) return false;

		//清除body折叠类名
		var body = $('#layout-body');
		body.hasClass('body_layout_west_collapse') && body.removeClass('body_layout_west_collapse');

		//开始获取左侧栏目
		$.ajax({
			type: 'POST',
			url: "<{:U('admin/Index/public_menuLeft')}>",
			data: {menuid: menuid},
			cache: false,
			beforeSend: function(){
				that.removeLeft();
				//更新标题名称
				$('body').layout('panel', 'west').panel({title: title});
				var loading = '<div class="panel-loading">Loading...</div>';
				$("#leftmenu").accordion("add", {content: loading});
			},
			success: function(data){
				that.removeLeft();
				//左侧内容更新
				$.each(data, function(i, menu) {
					var content = '';
					if(menu.son){
						var treedata = $.toJSON(menu.son);
						content = '<ul class="easyui-tree" data-options=\'data:' + treedata + ',animate:true,lines:true,onClick:function(node){ var linkurl = "/admin"+node.url; baseModule.openUrl(linkurl, node.text);}\'></ul>';
					}
					var iconName = that.leftMenuIcon[menu.name] || that.leftMenuIcon['默认设置'];
					$("#leftmenu").accordion("add", {title: menu.name, content: content, iconCls:'iconfont ' + iconName,selected:i == 0});
					//选中第一个
					// $('#leftmenu').accordion('select',0);
					that.setToggleBtn();
					var firstTreeNode = $('#leftmenu').accordion('getPanel',0).find('#_easyui_tree_1');
					firstTreeNode.addClass('tree-node-selected');
				});
			}
		});
		//默认选中头部菜单
		if(object){
			$('#topmenu .nav li').each(function(){
				$(this).children().removeClass('focus');
			});
			$(object).addClass('focus');
		}

		//如果左侧隐藏则进行展开
		if($('body').layout('panel', 'west').panel("options").collapsed){
			$('body').layout('expand', 'west');
		}
	},

	//显示打开内容
	openUrl: function(url, title){
		if($('#pagetabs').tabs('exists', title)){
			var tab = $('#pagetabs').tabs('getTab', title);
			$("#pagetabs").tabs('update',{
		        tab: tab,
		        options:{
		            href: url
		        }
		    });
		    //tab.panel('refresh');
		    $('#pagetabs').tabs('select', title);
		}else{
			$('#pagetabs').tabs('add',{title: title, href: url, closable: true, cache: true});
		}
	},

	//更新缓存
	clearCache: function(){
		$.post('<{:U('admin/Index/public_clearCatche')}>', function(data){
			var type = data.status ? 'info' : 'error';
			$.app.method.tip('提示信息', data.info, type);
		}, 'json');
	},

	//退出登录
	logout: function(){
		$.messager.confirm('提示信息', '确定要退出登录吗？', function(result){
			if(result) window.location.href = '<{:U('admin/Index/logout')}>';
		});
	},

	//服务器信息
	systemInfo: function(type){
		var that = this;
		$(that.dialog).dialog({
			title: '服务器信息',
			iconCls: 'icons-application-application_view_detail',
			width: 550,
			height: 400,
			cache: false,
			href: '<{:U('admin/Index/systemInfo')}>',
			modal: true,
			collapsible: false,
			minimizable: false,
			resizable: true,
			maximizable: true,
			buttons:[{
				text: '关闭',
				iconCls: 'icons-arrow-cross',
				handler: function(){
					$(that.dialog).dialog('close');
				}
			}]
		});
	},

	//防止登录超时
	sessionLife: function(){
		setInterval(function(){
			$.post('<{:U('admin/Index/public_sessionLife')}>', function(data){
				if(!data.status){
					$.messager.show({
						title: '系统提示',
						msg: data.info,
						timeout:3000,
						showType:'slide'
					});
					setTimeout(function(){
						window.location.href = data.url;
					}, 3000);
				}
			}, 'json');
		}, 15000);
	},

	//个人信息

	userinfo: function(){

		var that = this;
		$(that.dialog).dialog({
			title: '个人信息',
			iconCls: 'icons-application-application_view_detail',
			width: 360,
			height: 270,
			cache: false,
			href: '<{:U('admin/Admin/public_editInfo')}>',
			modal: true,
			collapsible: false,
			minimizable: false,
			resizable: false,
			maximizable: false,

			buttons:[{
				text:'关闭',
				iconCls:'icons-arrow-cross',
				handler: function(){
					$(that.dialog).dialog('close');
				}
			}]
		});

	},

	//修改密码
	password: function(){
		var that = this;
		$(that.dialog).dialog({
			title: '修改密码',
			iconCls: 'icons-application-application_form_edit',
			width: 360,
			height: 270,
			cache: false,
			href: "<{:U('admin/Admin/public_editPwd')}>",
			modal: true,
			collapsible: false,
			minimizable: false,
			resizable: false,
			maximizable: false,
			buttons:[{
				text: '确定',
				iconCls: 'icons-other-tick',
				handler: function(){
					$(that.dialog).find('form').eq(0).form('submit', {
						onSubmit: function(){
							var isValid = $(this).form('validate');
							if (!isValid) return false;

							$.messager.progress({text:'处理中，请稍候...'});
							$.post("<{:U('admin/Admin/public_editPwd?dosubmit=1')}>", $(this).serialize(), function(res){
								$.messager.progress('close');
								if(!res.status){
									$.app.method.tip('提示信息', res.info, 'error');
								}else{
									$.messager.confirm('提示信息', res.info, function(result){
										if(result) window.location.href = res.url;
									});
								}
							}, 'json');

							return false;
						}
					});
				}
			},{
				text: '取消',
				iconCls: 'icons-arrow-cross',
				handler: function(){
					$(that.dialog).dialog('close');
				}
			}]
		});
	},
    //首次登录修改密码
    initpassword: function(){
        var that = this;
        $(that.dialog).dialog({
            title: '首次登录需要修改密码',
            iconCls: 'icons-application-application_form_edit',
            width: 360,
            height: 270,
            cache: false,
            href:"<{:U('admin/Admin/public_editPwd')}>",
                modal: true,
                collapsible: false,
                minimizable: false,
                resizable: false,
                maximizable: false,
                draggable: false, //拖拽操作
                closable: false,//显示关闭按钮
                buttons:[{
            text: '确定',
            iconCls: 'icons-other-tick',
            handler: function(){
                $(that.dialog).find('form').eq(0).form('submit', {
                    onSubmit: function(){
                        var isValid = $(this).form('validate');
                        if (!isValid) return false;

                        $.messager.progress({text:'处理中，请稍候...'});
                        $.post("<{:U('admin/Admin/public_editPwd?dosubmit=1')}>", $(this).serialize(), function(res){
                            $.messager.progress('close');
                            if(!res.status){
                                $.app.method.tip('提示信息', res.info, 'error');
                            }else{
                                $.messager.confirm('提示信息', res.info, function(result){
                                    if(result) window.location.href = res.url;
                                });
                            }
                        }, 'json');

                        return false;
                    }
                });
            }
        }]
    });
    }
};
$(function(){baseModule.init();});
</script>
</body>
</html>
